package com.example.mountainwalker.service.impl;

import com.example.mountainwalker.entity.ScenicCommentInfo;
import com.example.mountainwalker.mapper.ScenicCommentMapper;
import com.example.mountainwalker.service.ScenicCommentService;
import com.example.mountainwalker.vo.ViewScenicComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScenicCommentImpl implements ScenicCommentService {

    @Autowired
    private ScenicCommentMapper scenicCommentMapper;

    @Override
    public List<ScenicCommentInfo> getScenicCommentInfo() {
        return scenicCommentMapper.getScenicCommentInfo();
    }

    @Override
    public ScenicCommentInfo getScenicCommentInfoById(Integer id) {
        return scenicCommentMapper.getScenicCommentInfoById(id);
    }

    @Override
    public int deleteScenicCommentInfoById(Integer id) {
        return scenicCommentMapper.deleteScenicCommentInfoById(id); // 调用Mapper的删除方法
    }

    @Override
    public int insertScenicCommentInfo(ScenicCommentInfo scenicCommentInfo) {
        return scenicCommentMapper.insertScenicCommentInfo(scenicCommentInfo);
    }

    @Override
    public int updateScenicCommentInfo(ScenicCommentInfo scenicCommentInfo) {
        return scenicCommentMapper.updateScenicCommentInfo(scenicCommentInfo);
    }

    @Override
    public PageResult<ViewScenicComment> getScenicCommentInfoByPage(PageRequest pageRequest) {
        int pageNum = pageRequest.getPageNum();
        int pageSize = pageRequest.getPageSize();
        int offset = (pageNum - 1) * pageSize;

        List<ViewScenicComment> list = scenicCommentMapper.getScenicCommentInfoByPage(offset, pageSize);
        int total = scenicCommentMapper.countScenicCommentInfo();

        return new PageResult<>(pageNum, pageSize, total, list);
    }

    @Override
    public ViewScenicComment getViewScenicCommentById(Integer id) {
        return scenicCommentMapper.getViewScenicCommentById(id);
    }
}